package com.daocao.sysuser.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.daocao.common.domain.entity.UmsUserDetail;
import com.daocao.common.response.DaoCaoResult;
import com.daocao.common.service.IUmsUserDetailService;

import jakarta.validation.Valid;

@RestController
@RequestMapping("sys/userDetail")
public class UserDetailController {

    @Autowired
    private IUmsUserDetailService userDetailService;

    @GetMapping("/info")
    public DaoCaoResult searchUserInfo() {
        return DaoCaoResult.success(userDetailService.searchById());
    }
    
    @PutMapping
    public DaoCaoResult updateDetail(@Valid @RequestBody UmsUserDetail umsUserDetail) {
        int row = userDetailService.updateDetail(umsUserDetail);
        if(row > 0) {
            return DaoCaoResult.success();
        }
        return DaoCaoResult.error("更新できませんでした。");
    }
}
